package idiet.view;

import idiet.Activator;
import idiet.bean.Customer;
import idiet.bean.CustomerNurse;
import idiet.bean.CustomerPal;
import idiet.bean.NurseTarget;
import idiet.service.CustomerNurseService;
import idiet.service.CustomerService;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.DateTime;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.part.ViewPart;
import org.eclipse.wb.swt.SWTResourceManager;

import swing2swt.layout.BorderLayout;

public class ViewPartCustomerTraceUpdate extends ViewPart {
	public static final String ID="iDiet.view.trace.customer.update";
	private List<Customer> customers=new ArrayList<Customer>();
	private CustomerService customerService=Activator.getApplicationContext().getBean(CustomerService.class);
	private CustomerNurseService customerNurseService=Activator.getApplicationContext().getBean(CustomerNurseService.class);
	private Text textCustomerName;
	private Text textName;
	private Table table;
	private Text textAge;
	private Text textHeight;
	private Text textWeight;
	private Text textComment;
	private Text textBust;
	private Text textWaist;
	private Text textHip;
	private Combo comboPal;
	private Combo comboTarget;
	private DateTime dateTimeStart;
	private DateTime dateTimeQueryStart;
	private DateTime dateTimeEnd;
	private DateTime dateTimeQueryEnd;
	private TableViewer tableViewer;
	private Button btnNewButtonCreateCustomerNurse;
	private CustomerNurse customerNurse;
	private Customer customer;
	private Text textPicture;
	public ViewPartCustomerTraceUpdate() {
	}

	@Override
	public void createPartControl(Composite parent) {
		parent.setLayout(new GridLayout(2, false));
		
		Composite composite = new Composite(parent, SWT.NONE);
		composite.setLayout(new GridLayout(5, false));
		GridData gd_composite = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
		gd_composite.widthHint = 300;
		composite.setLayoutData(gd_composite);
		
		Label lblNewLabel = new Label(composite, SWT.NONE);
		lblNewLabel.setText("Date of customer's information enter");
		
		dateTimeQueryStart = new DateTime(composite, SWT.BORDER | SWT.DROP_DOWN);
		dateTimeQueryStart.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		Calendar calendar=GregorianCalendar.getInstance();
		calendar.add(Calendar.DAY_OF_MONTH, -7);
		dateTimeQueryStart.setDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
		Label label = new Label(composite, SWT.NONE);
		label.setText("-");
		
		dateTimeQueryEnd = new DateTime(composite, SWT.BORDER | SWT.DROP_DOWN);
		new Label(composite, SWT.NONE);
		
		Label lblNewLabel_1 = new Label(composite, SWT.NONE);
		lblNewLabel_1.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblNewLabel_1.setText("Customer Name");
		
		textCustomerName = new Text(composite, SWT.BORDER);
		GridData gd_textCustomerName = new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1);
		gd_textCustomerName.widthHint = 172;
		textCustomerName.setLayoutData(gd_textCustomerName);
		
		Button btnNewButton = new Button(composite, SWT.NONE);
		btnNewButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				SimpleDateFormat format=new SimpleDateFormat("M/d/yyyy");
				//customer.setForeStartDate(format.parse(StringUtils.substringBetween(dateTimeStart.toString(), "{", "}")));
				if(textCustomerName.getText().trim().equals("")){
					
					if(dateTimeQueryStart.toString().equals(dateTimeQueryEnd.toString())){
						customers=customerService.getCustomers(null);
					}else{
						try {
							customers=customerService.getCustomers(null, new Timestamp(format.parse(StringUtils.substringBetween(dateTimeQueryStart.toString(), "{", "}")).getTime()), new Timestamp(format.parse(StringUtils.substringBetween(dateTimeQueryEnd.toString(), "{", "}")).getTime()));
						} catch (ParseException e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						}
					}
				}else{
					if(dateTimeQueryStart.toString().equals(dateTimeQueryEnd.toString())){
						customers=customerService.getCustomers(textCustomerName.getText());
					}else{
						try {
							customers=customerService.getCustomers(textCustomerName.getText(), new Timestamp(format.parse(StringUtils.substringBetween(dateTimeQueryStart.toString(), "{", "}")).getTime()), new Timestamp(format.parse(StringUtils.substringBetween(dateTimeQueryEnd.toString(), "{", "}")).getTime()));
						} catch (ParseException e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						}
					}
				}
				tableViewer.setInput(customers);
			}
		});
		GridData gd_btnNewButton = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
		gd_btnNewButton.widthHint = 91;
		btnNewButton.setLayoutData(gd_btnNewButton);
		btnNewButton.setText("Query");
		
		Composite composite_2 = new Composite(composite, SWT.NONE);
		composite_2.setLayout(new BorderLayout(0, 0));
		composite_2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 5, 1));
		
		tableViewer = new TableViewer(composite_2, SWT.BORDER | SWT.FULL_SELECTION);
		table = tableViewer.getTable();
		table.setLinesVisible(true);
		table.setHeaderVisible(true);
		table.setLayoutData(BorderLayout.CENTER);
		table.addSelectionListener(new SelectionAdapter(){

			@Override
			public void widgetSelected(SelectionEvent e) {
				// TODO Auto-generated method stub
				IStructuredSelection selections =(IStructuredSelection)tableViewer.getSelection();
				customer=(Customer)selections.getFirstElement();
				if(customer!=null){
					textName.setText(customer.getName());
					textAge.setText(new Integer(customer.getAge()).toString());
					List<CustomerNurse> nurses=customerNurseService.getCustomerNurses(customer);
					if(nurses.size()>0){
						CustomerNurse nurse=nurses.get(0);
						textAge.setText(new Integer(nurse.getAge()).toString());
						textHeight.setText(nurse.getHeight().toString());
						textWeight.setText(nurse.getWeight().toString());
						textComment.setText(nurse.getComment());
						textWaist.setText(nurse.getWaist().toString());
						textHip.setText(nurse.getHips().toString());
						textBust.setText(nurse.getBust().toString());
						//textPicture.setText();
						//comboPal.setText("");
						//comboTarget.setText("");
					}
				}
			}
		});
		tableViewer.setContentProvider(new ArrayContentProvider());
		TableViewerColumn tableViewerColumn = new TableViewerColumn(tableViewer, SWT.NONE);
		TableColumn tblclmnNewColumn = tableViewerColumn.getColumn();
		tblclmnNewColumn.setWidth(100);
		tblclmnNewColumn.setText("Name");
		tableViewerColumn.setLabelProvider(new ColumnLabelProvider(){
			@Override
			public String getText(Object element) {
				// TODO Auto-generated method stub
				return ((Customer)element).getName();
			}
		});
		
		TableViewerColumn tableViewerColumn_3 = new TableViewerColumn(tableViewer, SWT.NONE);
		TableColumn tblclmnNewColumn_3 = tableViewerColumn_3.getColumn();
		tblclmnNewColumn_3.setWidth(100);
		tblclmnNewColumn_3.setText("Gender");
		tableViewerColumn_3.setLabelProvider(new ColumnLabelProvider(){

			@Override
			public String getText(Object element) {
				// TODO Auto-generated method stub
				return ((Customer)element).getGender();
			}
		});
		
		TableViewerColumn tableViewerColumn_2 = new TableViewerColumn(tableViewer, SWT.NONE);
		TableColumn tblclmnNewColumn_2 = tableViewerColumn_2.getColumn();
		tblclmnNewColumn_2.setWidth(100);
		tblclmnNewColumn_2.setText("Nation");
		tableViewerColumn_2.setLabelProvider(new ColumnLabelProvider(){

			@Override
			public String getText(Object element) {
				// TODO Auto-generated method stub
				return ((Customer)element).getNation().getName();
			}
		});
		
		TableViewerColumn tableViewerColumn_4 = new TableViewerColumn(tableViewer, SWT.NONE);
		TableColumn tblclmnNewColumn_4 = tableViewerColumn_4.getColumn();
		tblclmnNewColumn_4.setWidth(100);
		tblclmnNewColumn_4.setText("Phone");
		tableViewerColumn_4.setLabelProvider(new ColumnLabelProvider(){
			@Override
			public String getText(Object element){
				return ((Customer)element).getTelephone();
			}
		});
		
		TableViewerColumn tableViewerColumn_1 = new TableViewerColumn(tableViewer, SWT.NONE);
		TableColumn tblclmnNewColumn_1 = tableViewerColumn_1.getColumn();
		tblclmnNewColumn_1.setWidth(100);
		tblclmnNewColumn_1.setText("Cellphone");
		tableViewerColumn_1.setLabelProvider(new ColumnLabelProvider(){

			@Override
			public String getText(Object element) {
				// TODO Auto-generated method stub
				return ((Customer)element).getCellphone();
			}
		});
		
		TableViewerColumn tableViewerColumn_5 = new TableViewerColumn(tableViewer, SWT.NONE);
		TableColumn tblclmnNewColumn_5 = tableViewerColumn_5.getColumn();
		tblclmnNewColumn_5.setWidth(100);
		tblclmnNewColumn_5.setText("Im");
		tableViewerColumn_5.setLabelProvider(new ColumnLabelProvider(){

			@Override
			public String getText(Object element) {
				// TODO Auto-generated method stub
				return ((Customer)element).getIm();
			}
		});
		
		TableViewerColumn tableViewerColumn_6 = new TableViewerColumn(tableViewer, SWT.NONE);
		TableColumn tblclmnNewColumn_6 = tableViewerColumn_6.getColumn();
		tblclmnNewColumn_6.setWidth(100);
		tblclmnNewColumn_6.setText("Adress");
		tableViewerColumn_6.setLabelProvider(new ColumnLabelProvider(){

			@Override
			public String getText(Object element) {
				// TODO Auto-generated method stub
				return ((Customer)element).getAddress();
			}
		});
		
		Composite composite_1 = new Composite(parent, SWT.NONE);
		composite_1.setLayout(new GridLayout(3, false));
		GridData gd_composite_1 = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
		gd_composite_1.widthHint = 352;
		composite_1.setLayoutData(gd_composite_1);
		
		Label lblNewLabel_2 = new Label(composite_1, SWT.NONE);
		lblNewLabel_2.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblNewLabel_2.setText("Name");
		
		textName = new Text(composite_1, SWT.BORDER);
		textName.setEditable(false);
		textName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
		
		Label lblAge = new Label(composite_1, SWT.NONE);
		lblAge.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblAge.setText("Age");
		
		textAge = new Text(composite_1, SWT.BORDER);
		textAge.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		textAge.addModifyListener(new ModifyListener(){

			@Override
			public void modifyText(ModifyEvent e) {
				// TODO Auto-generated method stub
				if(textAge.getText().trim().equals("")){
					//showErrorOnStatusline(BUNDLE.getString("View.Part.Customer.Add.age.is.empty"));
					btnNewButtonCreateCustomerNurse.setEnabled(false);
				}else{
					if(!StringUtils.isNumeric(textAge.getText())){
						textAge.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
						//showErrorOnStatusline(BUNDLE.getString("View.Part.Customer.Add.age.is.not.numeric"));
						btnNewButtonCreateCustomerNurse.setEnabled(false);
					}else{
						showErrorOnStatusline(null);
						textAge.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
						btnNewButtonCreateCustomerNurse.setEnabled(true);
					}
					
				}
			}
			
		});
		new Label(composite_1, SWT.NONE);
		
		Label lblHeight = new Label(composite_1, SWT.NONE);
		lblHeight.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblHeight.setText("Height");
		
		textHeight = new Text(composite_1, SWT.BORDER);
		textHeight.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		textHeight.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent e) {
				if(textHeight.getText().trim().equals("")){
					//showErrorOnStatusline(BUNDLE.getString("View.Part.Customer.Add.height.is.empty"));
					btnNewButtonCreateCustomerNurse.setEnabled(false);
				}else{
					if(!StringUtils.isNumeric(textHeight.getText())){
						//showErrorOnStatusline(BUNDLE.getString("View.Part.Customer.Add.height.is.not.numeric"));
						btnNewButtonCreateCustomerNurse.setEnabled(false);
						textHeight.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
					}else{
						showErrorOnStatusline(null);
						btnNewButtonCreateCustomerNurse.setEnabled(true);
						textHeight.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
					}
				}
			}
		});
		Label lblcm = new Label(composite_1, SWT.NONE);
		lblcm.setText("(cm)");
		
		Label lblWeight = new Label(composite_1, SWT.NONE);
		lblWeight.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblWeight.setText("Weight");
		
		textWeight = new Text(composite_1, SWT.BORDER);
		textWeight.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		textWeight.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent e) {
				if(textWeight.getText().trim().equals("")){
					//showErrorOnStatusline(BUNDLE.getString("View.Part.Customer.Add.weight.is.empty"));
					btnNewButtonCreateCustomerNurse.setEnabled(false);
				}else{
					if(!StringUtils.isNumeric(textWeight.getText())){
						//showErrorOnStatusline(BUNDLE.getString("View.Part.Customer.Add.weight.is.not.numeric"));
						btnNewButtonCreateCustomerNurse.setEnabled(false);
						textWeight.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
					}else{
						showErrorOnStatusline(null);
						btnNewButtonCreateCustomerNurse.setEnabled(true);
						textWeight.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
					}
				}
			}
		});
		Label lblkg = new Label(composite_1, SWT.NONE);
		lblkg.setText("(Kg)");
		
		Label lblBust = new Label(composite_1, SWT.NONE);
		lblBust.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblBust.setText("Bust");
		
		textBust = new Text(composite_1, SWT.BORDER);
		textBust.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		textBust.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent e) {
				if(!StringUtils.isNumeric(textBust.getText())){
					//showErrorOnStatusline(BUNDLE.getString("View.Part.Customer.Add.bust.is.not.numeric"));
					btnNewButtonCreateCustomerNurse.setEnabled(false);
					textBust.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
				}else{
					showErrorOnStatusline(null);
					btnNewButtonCreateCustomerNurse.setEnabled(true);
					textBust.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
				}
			}
		});
		Label lblcms = new Label(composite_1, SWT.NONE);
		lblcms.setText("(cm)");
		
		Label lblWaist = new Label(composite_1, SWT.NONE);
		lblWaist.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblWaist.setText("Waist");
		
		textWaist = new Text(composite_1, SWT.BORDER);
		textWaist.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		textWaist.addModifyListener(new ModifyListener(){

			@Override
			public void modifyText(ModifyEvent e) {
				// TODO Auto-generated method stub
				if(!StringUtils.isNumeric(textWaist.getText())){
					//showErrorOnStatusline(BUNDLE.getString("View.Part.Customer.Add.waist.is.not.numeric"));
					btnNewButtonCreateCustomerNurse.setEnabled(false);
					textWaist.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
				}else{
					showErrorOnStatusline(null);
					btnNewButtonCreateCustomerNurse.setEnabled(true);
					textWaist.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
				}
			}
		});
		Label lblcm_1 = new Label(composite_1, SWT.NONE);
		lblcm_1.setText("(cm)");
		
		Label lblHip = new Label(composite_1, SWT.NONE);
		lblHip.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblHip.setText("Hip");
		
		textHip = new Text(composite_1, SWT.BORDER);
		textHip.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		textHip.addModifyListener(new ModifyListener(){

			@Override
			public void modifyText(ModifyEvent e) {
				// TODO Auto-generated method stub
				if(!StringUtils.isNumeric(textHip.getText())){
					//showErrorOnStatusline(BUNDLE.getString("View.Part.Customer.Add.hip.is.not.numeric"));
					btnNewButtonCreateCustomerNurse.setEnabled(false);
					textHip.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
				}else{
					showErrorOnStatusline(null);
					btnNewButtonCreateCustomerNurse.setEnabled(true);
					textHip.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
				}
			}
			
		});
		Label lblcm_2 = new Label(composite_1, SWT.NONE);
		lblcm_2.setText("(cm)");
		
		Label lblCustomerPal = new Label(composite_1, SWT.NONE);
		lblCustomerPal.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblCustomerPal.setText("Customer Pal");
		
		comboPal = new Combo(composite_1, SWT.NONE);
		comboPal.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		new Label(composite_1, SWT.NONE);
		
		Label lblNurseTarget = new Label(composite_1, SWT.NONE);
		lblNurseTarget.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblNurseTarget.setText("Nurse Target");
		
		comboTarget = new Combo(composite_1, SWT.NONE);
		comboTarget.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		new Label(composite_1, SWT.NONE);
		
		Label lblForecastStart = new Label(composite_1, SWT.NONE);
		lblForecastStart.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblForecastStart.setText("Forecast Start Date");
		
		dateTimeStart = new DateTime(composite_1, SWT.BORDER);
		dateTimeStart.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		new Label(composite_1, SWT.NONE);
		
		Label lblForecastEndDate = new Label(composite_1, SWT.NONE);
		lblForecastEndDate.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblForecastEndDate.setText("Forecast End Date");
		
		dateTimeEnd = new DateTime(composite_1, SWT.BORDER);
		dateTimeEnd.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		new Label(composite_1, SWT.NONE);
		Calendar calendar2=GregorianCalendar.getInstance();
		calendar2.add(Calendar.DAY_OF_MONTH, 30);
		dateTimeEnd.setDate(calendar2.get(Calendar.YEAR), calendar2.get(Calendar.MONTH), calendar2.get(Calendar.DAY_OF_MONTH));
		
		Label lblComment = new Label(composite_1, SWT.NONE);
		lblComment.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
		lblComment.setText("Comment");
		
		textComment = new Text(composite_1, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL | SWT.MULTI);
		GridData gd_textComment = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
		gd_textComment.heightHint = 59;
		textComment.setLayoutData(gd_textComment);
		
		Composite composite_3 = new Composite(composite_1, SWT.NONE);
		composite_3.setLayout(new GridLayout(4, false));
		composite_3.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 3, 1));
		
		Label lblPicture = new Label(composite_3, SWT.NONE);
		lblPicture.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblPicture.setText("Picture");
		
		textPicture = new Text(composite_3, SWT.BORDER);
		textPicture.setEditable(false);
		textPicture.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Button btnBowser = new Button(composite_3, SWT.NONE);
		btnBowser.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
			}
		});
		GridData gd_btnBowser = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
		gd_btnBowser.widthHint = 62;
		btnBowser.setLayoutData(gd_btnBowser);
		btnBowser.setText("Bowser");
		
		btnNewButtonCreateCustomerNurse = new Button(composite_3, SWT.NONE);
		GridData gd_btnNewButtonCreateCustomerNurse = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
		gd_btnNewButtonCreateCustomerNurse.widthHint = 68;
		btnNewButtonCreateCustomerNurse.setLayoutData(gd_btnNewButtonCreateCustomerNurse);
		btnNewButtonCreateCustomerNurse.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				if(textAge.getText().trim().equals("")){
			//		showErrorOnStatusline(BUNDLE.getString("View.Part.Customer.Add.age.is.empty"));
					btnNewButtonCreateCustomerNurse.setEnabled(false);
					return;
				}
				if(textHeight.getText().trim().equals("")){
			//		showErrorOnStatusline(BUNDLE.getString("View.Part.Customer.Add.height.is.empty"));
					btnNewButtonCreateCustomerNurse.setEnabled(false);
					return;
				}
				if(textWeight.getText().trim().equals("")){
			//		showErrorOnStatusline(BUNDLE.getString("View.Part.Customer.Add.weight.is.empty"));
					btnNewButtonCreateCustomerNurse.setEnabled(false);
					return;
				}
				customerNurse=new CustomerNurse();
				customerNurse.setCustomer(customer);
				customerNurse.setAge(Integer.parseInt(textAge.getText()));
				customerNurse.setHeight(new BigDecimal(textHeight.getText()));
				customerNurse.setWeight(new BigDecimal(textWeight.getText()));
				
				customerNurse.setWaist(new BigDecimal(textWaist.getText()));
				customerNurse.setHips(new BigDecimal(textHip.getText()));
				customerNurse.setBust(new BigDecimal(textBust.getText()));
				if(!comboPal.getText().trim().equals("")){
					CustomerPal pal=new CustomerPal();
					pal.setId(Integer.parseInt(comboPal.getData(comboPal.getText()).toString()));
					pal.setName(comboPal.getText());
					customerNurse.setCustomerPal(pal);
				}else{
					customerNurse.setCustomerPal(null);
				}
				if(!comboTarget.getText().trim().equals("")){
					NurseTarget target=new NurseTarget();
					target.setId(Integer.parseInt(comboTarget.getData(comboTarget.getText()).toString()));
					target.setName(comboTarget.getText());
					customerNurse.setNurseTarget(target);
				}else{
					customerNurse.setCustomerPal(null);
				}
				Calendar startTime = GregorianCalendar.getInstance();
				startTime.set(dateTimeStart.getYear(), dateTimeStart.getMonth(), dateTimeStart.getDay(), dateTimeStart.getHours(), dateTimeStart.getMinutes());
				customerNurse.setForeStartDate(startTime.getTime());
				Calendar endTime=GregorianCalendar.getInstance();
				endTime.set(dateTimeEnd.getYear(), dateTimeEnd.getMonth(), dateTimeEnd.getDay(),dateTimeEnd.getHours(), dateTimeEnd.getMinutes());
				customerNurse.setForeEndDate(endTime.getTime());
				customerNurse.setComment(textComment.getText());
				customerNurseService.createCustomerNurse(customerNurse);
				
				textName.setText("");
				
				textHeight.setText("");
				textWeight.setText("");
				textComment.setText("");
				textAge.setText("");
				textWaist.setText("");
				textHip.setText("");
				textBust.setText("");
				textPicture.setText("");
				comboPal.setText("");
				comboTarget.setText("");
				//dateTimeForecastStart.set;
				//dateTimeForecastEnd;
				btnNewButtonCreateCustomerNurse.setSelection(true);
				showErrorOnStatusline(null);
			}
		});
		btnNewButtonCreateCustomerNurse.setText("Save");
		
		Group group = new Group(composite_1, SWT.NONE);
		group.setLayout(new BorderLayout(0, 0));
		group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));
		
		Canvas canvasPicture = new Canvas(group, SWT.NONE);
		// TODO Auto-generated method stub

	}

	@Override
	public void setFocus() {
		// TODO Auto-generated method stub

	}
	protected void showErrorOnStatusline(String error) {
		IStatusLineManager statusline = this.getViewSite().getActionBars().getStatusLineManager();
		if (error == null) {
			statusline.setErrorMessage(null, error);
		} else {
			statusline.setErrorMessage(null, error);
		} 
	}
}
